/*
 * Licensed to the 南京汇海交通科技有限公司
 *
 * Copyright (c) 2025.
 * All rights reserved.
 *
 * 本软件属南京汇海交通科技有限公司所有，在未获得南京汇海交通科技有限公司正式授权情况下，任何企业和个人，不能获取、阅读、安装、传播本软件涉及的任何受知识产权保护的内容。
 */
package com.chframework.cloud.web.openfeign;

import feign.Client;
import feign.Request;
import feign.Response;

import javax.net.ssl.HostnameVerifier;
import javax.net.ssl.SSLSocketFactory;
import java.io.IOException;

/**
 * 实现响应拦截的核心代码：
 * 代理Feign默认的Client
 */
public final class DefaultClientWrapper extends Client.Default {

    private FeignClientResponseAdvice advice;

    public DefaultClientWrapper(SSLSocketFactory sslContextFactory, HostnameVerifier hostnameVerifier, FeignClientResponseAdvice advice) {
        super(sslContextFactory, hostnameVerifier);
        this.advice = advice;
    }

    @Override
    public Response execute(Request request, Request.Options options) throws IOException {
        Response response = super.execute(request, options);
        if (advice != null) {
            advice.returnAdvice(response, options);
        }
        return response;
    }

}
